StyleRun Class

Used to manage a style run within StyledText.

Events

None

Properties

Bold

Font

Italic

Size

Text

TextColor

Underline


Methods

None

More information available in parent classes: Object


Notes

A StyleRun is a series of consecutive characters that have the same style attributes, as indicated by the StyleRun's properties. The Text property of a StyledText object is a series of StyleRuns.

You can get the total number of StyleRuns via the StyleRunCount method of the StyledText class and reference a StyleRun via the StyleRun method. You can get the starting and ending character positions (and, therefore, the length) of a StyleRun via the StyleRunRange method. The Range class gives you access to the StyleRun's start position, length, and end position.

If you are displaying the styled text in an EditField, changes to a StyleRun's properties are not reflected in the EditField. If you want to operate on a StyleRun, you must remove the old run and replace it with the new run. Of course, the easier way to update styled text in an EditField is to make your changes using the StyledText methods instead of the StyleRun properties.


Example

The following example saves styled text displayed in an EditField as a series of StyleRuns that are appended to one another.

Dim out as BinaryStream
out = DesktopFolder.Child("TestFile").CreateBinaryFile("")
  
//If we couldn't create the file, then bail out
If out = Nil then Return
  
//Now we want to loop over all the StyleRuns
//and dump them out to the file.
Dim mb as MemoryBlock
Dim sr as StyleRun
Dim i, Count as Integer
Dim TextLen, FontLen as Integer
Dim StaticInfo as Integer
  
//We already know that a style run takes up a certain amount of space
//3 bytes for the booleans, 2 for size and 4 for color
staticInfo = 1 + 1 + 1 + 2 + 4
  
//Get the number of styles
count = EditField1. StyledText.StyleRunCount
For i = 0 to Count-1  //get the StyleRuns
 sr = EditField1. StyledText.StyleRun( i )

 textLen = Len(sr.Text) + 1
 fontLen = Len(sr.Font) + 1

//Stuff the style run content and style info into a memory block
 mb = New MemoryBlock( staticInfo + fontLen + textLen )
 mb.BooleanValue(0) = sr.Bold
 mb.BooleanValue(1) = sr.Italic
 mb.BooleanValue(2) = sr.Underline
 mb.Short(3) = sr.Size
 mb.ColorValue(5, 32) = sr.TextColor
 mb.CString(9) = sr.Font
 mb.CString(9 + fontLen) = sr.Text
    
//Now we can write that information to the file
 out.Write(mb)
Next
  
out.Close  //close the file

See Also

EditField, Paragraph, Range, StyledText classes.